package cn.lrwjz.androidguide.ui.exmple.fragment;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * Fragment基类，用于演示Fragment的生命周期
 */
public class BaseFragment extends Fragment {
    private static final String TAG = "BaseFragment";
    protected String fragmentName;

    public BaseFragment() {
        fragmentName = this.getClass().getSimpleName();
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        Log.d(TAG, fragmentName + ": onAttach");
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, fragmentName + ": onCreate");
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        Log.d(TAG, fragmentName + ": onCreateView");
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Log.d(TAG, fragmentName + ": onViewCreated");
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.d(TAG, fragmentName + ": onStart");
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.d(TAG, fragmentName + ": onResume");
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.d(TAG, fragmentName + ": onPause");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.d(TAG, fragmentName + ": onStop");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.d(TAG, fragmentName + ": onDestroyView");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, fragmentName + ": onDestroy");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Log.d(TAG, fragmentName + ": onDetach");
    }
} 